package module.service.impl;

import common.bean.SearchPageResult;
import common.bean.SearchParameter;
import module.dao.AssessmentItemDao;
import module.dao.UserDao;
import module.model.AssessmentItemModel;
import module.service.AssessmentItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * 资料项
 */
@Service
public class AssessmentItemServiceImpl  implements AssessmentItemService {
    @Autowired
    private AssessmentItemDao assessmentItemDao;

    @Transactional
    public AssessmentItemModel saveAssessmentItemModel(AssessmentItemModel assessmentItemModel) {
        if(assessmentItemModel.getItemId()==null){
            assessmentItemModel.setCreateDate(new Date());
            assessmentItemDao.save(assessmentItemModel);
        }else{
            assessmentItemDao.update(assessmentItemModel);
        }
        return assessmentItemModel;
    }

    @Transactional
    public List<AssessmentItemModel> getAssessmentItemModelListBySearchParameter(SearchParameter searchParameter) {
        return assessmentItemDao.getAssessmentItemModelListBySearchParameter(searchParameter);
    }

    @Transactional
    public List<AssessmentItemModel> getAssessmentItemModelList(Long dataId, Long formId) {
        SearchParameter searchParameter = new SearchParameter();
        searchParameter.addParam("dataId",dataId);
        searchParameter.addParam("formId",formId);
        return getAssessmentItemModelListBySearchParameter(searchParameter);
    }
    @Transactional
    public void deleteAssessmentItemModelById(Long itemId) {
        assessmentItemDao.deleteById(AssessmentItemModel.class,itemId);
    }
    @Transactional
    public AssessmentItemModel getAssessmentItemModelByItemId(Long itemId) {
        return assessmentItemDao.load(AssessmentItemModel.class,itemId);
    }
    @Transactional
    public SearchPageResult<AssessmentItemModel> getAssessmentItemModelListPage(SearchParameter searchParameter) {
        return assessmentItemDao.getAssessmentItemModelListPage(searchParameter);
    }
}
